package thread;
import java.util.*;
public class SyncAPIDemo2 {
    public static void main(String[] args) {
      //  Set<Integer> c=new HashSet<>();
        List<Integer> c= Collections.synchronizedList(new ArrayList<>());

        Thread t1 =new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    c.add(i);
                }
            }
        };
        Thread2 t2=new Thread2(){
          public void run(){
              for (int i = 1000; i < 2000; i++){
                  c.add(i);
              }
          }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(c.size());
    }
}